package mo.leetcode_top;

public class L28 {

    public int strStr(String haystack, String needle) {
        int len = needle.length();
        int all = haystack.length();
        if (len == 0) {
            return 0;
        }
        if (all < len) {
            return -1;
        }
        for (int i = 0; i < all; i++) {
            int right = all - i;
            if (right < len) {
                break;
            }
            boolean same = true;
            for (int j = i; j < i+len; j++) {
                if (haystack.charAt(j) != needle.charAt(j-i)) {
                    same = false;
                    break;
                }
            }
            if (same) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        L28 test = new L28();
        System.out.println(test.strStr("aaaaaa", "aaaaaa"));
    }
}
